package tutorial;
import java.util.Date;
import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;

import chanfoofoo.* ; 

import com.opensymphony.xwork2.ActionSupport;
public class StockList extends ActionSupport implements SessionAware {
    public String MESSAGE = "Struts is up and running ...";
    Map<String, Object> session = null ; 
    private User currentUser =  null ; 
    private String message;
    private StockQuote_manager stockquote_manager = null ; // new StockQuote_manager(); 
 
    public String execute() throws Exception {
    	// setCurrentUser((User)session.get("currentUser"));
    	System.out.println("Running : HelloWorld.execute()..." ) ;
        setMessage(MESSAGE);
        return SUCCESS;
    }

    public String doSave() {    
    	session.put("currentUser" , currentUser) ; 
    	User_manager um = new User_manager() ; 
    	um.saveUser(currentUser) ; 
    	
    	System.out.println("Running : HelloWorld.doSave()...") ;	
    	stockquote_manager.userAction("SAVE") ; 
    	return SUCCESS ; 
    }
    

    public void setMessage(String message){
        this.message = message;
    }

    public String getMessage() {
    	message = (new Date()).toString() ; 
        return message ;
    }

	public void setStockquote_manager(StockQuote_manager stockquote_manager) {
		this.stockquote_manager = stockquote_manager;
	}

	public StockQuote_manager getStockquote_manager() {
		return stockquote_manager;
	}

	@Override
	public void setSession(Map<String, Object> arg0) {
		// TODO Auto-generated method stub
		session = arg0;
		currentUser = (User)session.get("currentUser") ; 
    	stockquote_manager = new StockQuote_manager();
    	if (currentUser != null) {
    		stockquote_manager.setCurrentUser(currentUser) ;
    		stockquote_manager.list_all_to_console() ;
    	}
	}

	public void setCurrentUser(User currentUser) {
		this.currentUser = currentUser;
	}
	public User getCurrentUser() {
		return currentUser;
	}
}